using System;

namespace ActivUFRJ.Classes.Geral
{
    public class DBFormacaoAcademica : Connection.MySQL
    {
        public DBFormacaoAcademica() : base(ref Connection.DBConnection.myConnection)
        {

        }

        private void FillFormacaoAcademica(FormacaoAcademica formacaoAcademica)
        {
            formacaoAcademica.ID = Convert.ToInt32(this.TableGetValue("FA_ID"));
            formacaoAcademica.Descricao = Convert.ToString(this.TableGetValue("FA_Descricao"));
        }

        internal FormacaoAcademica[] GetListaFormacaoAcademica()
        {
            try
            {
                string SQL = "SELECT * from FORMACOES_ACADEMICAS";

                this.SetSQL(SQL);

                int i = 0;
                FormacaoAcademica[] listaFormacoesAcademicas = new FormacaoAcademica[this.GetRowCount()];

                while (i < this.GetRowCount())
                {
                    FormacaoAcademica novaFA = new FormacaoAcademica();
                    this.FillFormacaoAcademica(novaFA);
                    listaFormacoesAcademicas[i] = novaFA;

                    i++;
                    this.TableMoveNext();
                }

                return listaFormacoesAcademicas;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        internal bool CarregarFormacaoAcademica(FormacaoAcademica formacaoAcademica)
        {
            try
            {
                string SQL = "SELECT * from FORMACOES_ACADEMICAS where FA_ID = " + formacaoAcademica.ID.ToString();

                this.SetSQL(SQL);
                if (!this.IsTableOver())
                {
                    FillFormacaoAcademica(formacaoAcademica);
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        internal System.Data.DataTable GetListaFormacoesDT()
        {
            try
            {
                string SQL = "SELECT * from formacoes_academicas";

                this.SetSQL(SQL);

                this.SetSQL(SQL);
                return this.ReturnTable();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
